
// <copyright file="ListAdapter.cs" company="Subhadra Software Solutions">
//   
// </copyright>
// <summary>
//   The list adapter.
// </summary>

namespace SubhadraSolutions.Sharp.Utils.Collections.Generic
{
    using System.Collections.Generic;

    /// <summary>
    /// The list adapter.
    /// </summary>
    /// <typeparam name="T">
    /// </typeparam>
    public class ListAdapter<T> : IDataStructureAdapter<T>
    {
        #region Fields

        /// <summary>
        /// The adaptedObject.
        /// </summary>
        protected IList<T> adaptedObject;

        /// <summary>
        /// The capacity int.
        /// </summary>
        protected int _capacityInt = -1;

        #endregion Fields

        #region Constructors and Finalizers

        /// <summary>
        /// Initializes a new instance of the <see cref="ListAdapter{T}"/> class.
        /// </summary>
        /// <param name="adaptedObject">
        /// The adaptedObject.
        /// </param>
        public ListAdapter(IList<T> adaptedObject)
        {
            this.adaptedObject = adaptedObject;
            this._capacityInt = this.adaptedObject.Count;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ListAdapter{T}"/> class.
        /// </summary>
        /// <param name="adaptedObject">
        /// The adaptedObject.
        /// </param>
        /// <param name="capacity">
        /// The capacity.
        /// </param>
        public ListAdapter(IList<T> adaptedObject, int capacity)
        {
            this.adaptedObject = adaptedObject;
            this._capacityInt = capacity;
        }

        #endregion Constructors and Finalizers

        #region Public Properties

        /// <summary>
        /// Gets the capacity.
        /// </summary>
        public virtual int Capacity
        {
            get
            {
                return this._capacityInt;
            }

            // set { _capacityInt = value; }
        }

        /// <summary>
        /// Gets the count.
        /// </summary>
        public int Count
        {
            get
            {
                return this.adaptedObject.Count;
            }
        }

        #endregion Public Properties

        #region Public Indexers

        /// <summary>
        /// The this.
        /// </summary>
        /// <param name="index">
        /// The index.
        /// </param>
        /// <returns>
        /// The <see cref="T"/>.
        /// </returns>
        public T this[int index]
        {
            get
            {
                return this.adaptedObject.Count > index ? this.adaptedObject[index] : default(T);
            }

            set
            {
                if (this.adaptedObject.Count > index)
                {
                    this.adaptedObject[index] = value;
                }
            }
        }

        #endregion Public Indexers

        #region Public Methods and Operators

        /// <summary>
        /// The clear.
        /// </summary>
        public void Clear()
        {
            this.adaptedObject.Clear();
        }

        #endregion Public Methods and Operators
    }
}